//
//  UIView+ZXZToast.m
//  zuxianzhi
//
//  Created by tyu on 28.5.24.
//

#import "UIView+ZXZToast.h"


@implementation UIView (ZXZToast)



+ (UITextField *)textfieldPlaceholder:(NSString *)placeholder keyboardType:(UIKeyboardType )keyboardType
{
    UITextField *TextF=[[UITextField alloc]init];
    TextF.borderStyle=UITextBorderStyleNone;
    TextF.placeholder = placeholder;
    TextF.keyboardType = keyboardType;
    return TextF;
}


+ (UILabel *)lableWithText:(NSString *)title andColor:(UIColor *)color andFont:(CGFloat )font
{
    
    UILabel *rightTitle  = [[UILabel alloc]init];
    rightTitle.font = [UIFont systemFontOfSize:font];
    rightTitle.textColor = color;
    rightTitle.text = title;
    return rightTitle;
}


- (CAShapeLayer *)setViewLeftTop:(CGFloat)leftC andRightTop:(CGFloat)rightC andView:(UIView *)view{

   UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(leftC, rightC)];
   CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
   maskLayer.frame = view.bounds;
   maskLayer.path = maskPath.CGPath;
   return maskLayer;
}





+ (UIColor *)ColorWithHexString:(NSString *)color alpha:(CGFloat)alpha {

    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    // String should be 6 or 8 characters
    if ([cString length] < 6)
    {
        return [UIColor clearColor];
    }

    if ([cString hasPrefix:@"0X"])
    {
        cString = [cString substringFromIndex:2];
    }
    if ([cString hasPrefix:@"#"])
    {
        cString = [cString substringFromIndex:1];
    }
    if ([cString length] != 6)
    {
        return [UIColor clearColor];
    }
    
    NSRange range;
    range.location = 0;
    range.length = 2;
    //r
    NSString *rString = [cString substringWithRange:range];
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha];
}

+ (UIColor *)ColorWithHexString:(NSString *)color {
    return [self ColorWithHexString:color alpha:1.0f];
}




+ (UIViewController *)createControllerById:(NSString *)Id
                             storyboadName:(NSString *)storyboadName
                                    bundle:(NSBundle *)bundle
{
    bundle = bundle ? bundle : [NSBundle mainBundle];
    storyboadName = storyboadName ? storyboadName : @"Main";
    UIViewController *vc = [[UIStoryboard storyboardWithName:storyboadName bundle:bundle] instantiateViewControllerWithIdentifier:Id];
    return vc;
}
@end
